package com.ignoreexception.exception;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 只要注册到容器中就生效
 * @author xD
 * @since 2022/12/26 19:56
 */
//@Component
public class CustomHandlerExceptionResolver implements HandlerExceptionResolver {
    /**
     *
     * 异常处理程序 ,渲染异常视图,这里一般前端提供异常页面jsp,可以不写
     * @param handler 抛出异常的Handler
     * @param exception Handler抛出的异常
     * @since 2022/12/26 17:21
     */
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest,
                                         HttpServletResponse httpServletResponse,
                                         Object handler,
                                         Exception exception) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/exception.jsp");
        return modelAndView;
    }
}
